﻿
@{
    ViewData["Title"] = "Login";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>登录</h2>
<form>
    <div class="form-group">
        <label for="username">用户名:</label>
        <input type="text" class="form-control" id="username" name="username">
    </div>
    <div class="form-group">
        <label for="password">密码:</label>
        <input type="password" class="form-control" id="password" name="password">
    </div>
    <input type="button" onclick="btnLogin()" value="提交">
</form>

<script type="text/javascript">
	function btnLogin(){
		var name = $.trim($("#username").val());
		var pwd = $.trim($("#password").val());

        if(name=="")
        {
            alert("用户名不能为空");
        }
        else if(pwd=="")
        {
            alert("密码不能为空");
        }
        else{
            var params={};
            params.username=name;
            params.userpwd=pwd;

            $.ajax({
                url:'/Account/LoginPost',
                type:'post',
                data:params,
                dataType:'json',
                async:true,
                error:function(){
                    alert('登陆失败！');
                },
                success:function(data){
                    if(data.code=='success'){
                        alert('登陆成功');
                        window.location.href='/';
                    }
                    else{
                        alert(data.msg);
                    }
                }
            });
        }
	}
</script>

